package net.zjitc.utils;

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class MailUtils {
    public static void  sendMail(String to,String code) throws Exception {
        Properties prop = new Properties();
        prop.setProperty("mail.host","smtp.qq.com");
        prop.setProperty("mail.smtp.auth","true");
        prop.setProperty("mail.smtp.port", "587");
        Authenticator authenticator = new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("370268540@qq.com", "yabkkclbhjvxbhde");
            }
        };
        Session session = Session.getInstance(prop,authenticator);
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("1107120908@qq.com"));
        message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
        message.addRecipient(Message.RecipientType.CC,new InternetAddress("1107120908@qq.com"));
        message.setSubject("自己的邮件");
        String content = "<a href=\"http://localhost:8080/shop1/activeCode?code="+code+"\">http://localhost:8080/shop/activeCode?code="+code+"</a>";
        message.setContent(content,"text/html;charset=utf-8");
        Transport.send(message);


    }
}
